using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using LeisureCenter.Controls;

namespace LeisureCenter.OptionsForms
{
    public partial class LibraryFolderOptionsDialog : LeisureCenter.Forms.DialogControl
    {
        private LeisureCenterDataSet.FilesDataTable filesDataTable;

        public LibraryFolderOptionsDialog(LeisureCenterDataSet.FilesDataTable filesDataTable)
        {
            InitializeComponent();
            this.filesDataTable = filesDataTable;
            foreach (LeisureCenterDataSet.FilesRow row in this.filesDataTable)
            {
                long rating = 0;
                if (!row.IsRatingNull())
                    rating = row.Rating;
                listBox1.Items.Add(new RatingListItem(listBox1, Path.GetFileName(row.Filename), "", rating));
            }
        }

        public override bool Execute()
        {
            bool result = base.Execute();
            if (result)
            {
                int i = 0;
                foreach (LeisureCenterDataSet.FilesRow row in this.filesDataTable)
                {
                    long rating = ((RatingListItem)listBox1.Items[i]).Rating;
                    if (rating == 0)
                        row.SetRatingNull();
                    else
                        row.Rating = rating;
                    i++;
                }
            }
            return result;
        }

        public override void SetFocusHandlers(LeisureCenter.Api.IFocusHandler okButton, LeisureCenter.Api.IFocusHandler cancelButton)
        {
            listBox1.FocusDown = okButton;
            btnRefresh.FocusUp = okButton;
        }
    }
}
